package com.studio49.exmple.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 
 * @author chensj
 * @date 2019年2月19日  上午9:42:06
 * @version 1.0
 */
@Configuration
public class RedisConfig {

	
	@SuppressWarnings("rawtypes")
	@Autowired
	private RedisTemplate redisTemplate;
	
	//解决redis储存乱码
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Bean
	public RedisTemplate redisTemplateInit() { 
		Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); 
		// 设置序列化Key的实例化对象 
		redisTemplate.setKeySerializer(new StringRedisSerializer()); 
		// 设置序列化Value的实例化对象 
		redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); 
		redisTemplate.setHashKeySerializer(jackson2JsonRedisSerializer); 
		redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); 
		return redisTemplate; 
	}
}
	

